﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Win32;
using Cll;

namespace LiveWriterBackupWPF
{
    public static class Xml2Reg
    {
        public static void Export(string regKey, string xmlFile)
        {
            if (regKey.Length == 0)
            {
                throw new NullReferenceException("registry key is empty");
            }
            if (xmlFile.Length == 0)
            {
                throw new NullReferenceException("xml file location empty");
            }
            if (xmlRegistry.keyExists(regKey))
            {
                xmlWriter w = new xmlWriter();
                xmlRegistry xmlReg = new xmlRegistry();

                w.open(xmlFile);
                xmlElement wroot = new xmlElement(xmlRegistry.XML_ROOT);
                wroot.write(w, 1, false, true);
                xmlReg.saveAsXml(w, false, regKey, "");
                wroot.writeClosingTag(w, -1, false, true);
               w.close();
            }
        }

        public static void Import(string xmlFile)
        {
            if (xmlFile.Length == 0)
            {
                throw new NullReferenceException("xml file location empty");
            }
            xmlReader xmlReader = new xmlReader();
            xmlRegistry xmlReg = new xmlRegistry();

            xmlReg.loadAsXml(xmlReader, xmlFile);
        }
    }
}
